package com.wyj.service.impl;

import com.google.common.collect.Maps;
import com.wyj.dto.result.FeatureResult;
import com.wyj.dto.data.LoginFormDTO;
import com.wyj.dto.result.Result;
import com.wyj.dto.data.UserGlobalData;
import com.wyj.service.FeaturesRemoteService;
import com.wyj.service.UserGlobalDataService;
import com.wyj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserGlobalDataService userGlobalDataService;

    @Autowired
    FeaturesRemoteService featuresRemoteService;

    @Override
    public Result login(LoginFormDTO loginFormDTO) {
        //1.效验登录

        //2.获取用户的全局数据
        UserGlobalData globalData = userGlobalDataService.getUserGlobalDataByUuid(loginFormDTO.getUuid());
        //3.调用全局的活动数据
        FeatureResult featureResult = featuresRemoteService.getAllFeatureConfig(globalData);
        //4.保存数据
        userGlobalDataService.saveUserGlobalData(globalData, loginFormDTO.getUuid());
        Map<String, Object> loginResult = Maps.newHashMap();
        loginResult.put("featureResult", featureResult);
        return Result.ok(loginResult);
    }
}
